package com.wanxi.service.message.impl;

import com.wanxi.dao.message.MessageDao;
import com.wanxi.dao.message.impl.MessageDaoImpl;
import com.wanxi.domain.PageModel;
import com.wanxi.domain.ResultModel;
import com.wanxi.domain.message.MessageModel;
import com.wanxi.service.message.MessageService;
import com.wanxi.util.MailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageDao messageDao;

    //插入数据
    @Override
    public int insert(MessageModel messageModel) {
        int num = messageDao.insert(messageModel);
       /* ResultModel resultModel = new ResultModel();
        resultModel.setData("我们会尽快回复您的反馈，请留意邮箱");
        if(num>0){
            resultModel.setMsg("success");
        }else {
            resultModel.setMsg("error");
        }*/
        return num;
    }

    //数据全查
    @Override
    public  List<MessageModel> selectAll(int page,int limit) {
        List<MessageModel> lists =  messageDao.selectAll(page,limit);

       /* ResultModel resultModel = new ResultModel();
        resultModel.setData(lists);*/
        return lists;
    }

    //获取反馈数据条数
    @Override
    public int getCount() {
       int num  =  messageDao.getCount();

      /*  ResultModel resultModel = new ResultModel();
        resultModel.setData(num);*/

        return num;
    }

    //通过id将该条数据的回复状态置为回复
    @Override
    public int updateById(String id) {
        int i =  messageDao.updateById(id);
       /* ResultModel resultModel = new ResultModel();
        resultModel.setData(i);*/
        return i;
    }

    //发送消息给反馈者
    @Override
    public String sendQQ(MessageModel messageModel) {
        return  MailUtil.sendMail(messageModel.getSubject(),messageModel.getEmail(),messageModel.getFeedback());
    }

    //通过id查询反馈邮箱
    @Override
    public MessageModel findById(int id) {
        MessageModel messageModel = messageDao.findById(id);
       /* ResultModel resultModel = new ResultModel();
        resultModel.setData(messageModel);*/
        return messageModel;
    }

    //删除用户反馈
    @Override
    public int delete(String id) {
        int num = messageDao.delete(id);
        return num;
    }
}
